package com.yanqu.road.server.logic.task.condition;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.entity.task.TaskInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.SecretVolumeModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;
import com.yanqu.road.server.manger.config.TaskMgr;

import java.math.BigInteger;

/**
 * 密卷经验等级
 */
public class SecretVolumeLevelCondition extends BaseCondition {

	public SecretVolumeLevelCondition(TaskConditionInfo conditionInfo, BaseTaskData quest, BigInteger value, Object initArgs) {
		super(conditionInfo, quest, value, initArgs);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.SecretVolumeExp.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.SecretVolumeExp.getValue(), handle);
	}

	public boolean isCompleted(GamePlayer player) {
		if(!player.getModule(SecretVolumeModule.class).isNowInTime()){
			return false;
		}
		BigInteger param4 = taskConditionInfo.getParamList().get(3);
		TaskInfo taskInfo = TaskMgr.getTaskInfoById(taskConditionInfo.getTaskId());
		//1免費2付費
		if(taskInfo.getLittleType() == 2){
			if(getValue().compareTo(param4) >= 0 && player.getModule(SecretVolumeModule.class).isBuySecretVolume()){
				return true;
			}else{
				return false;
			}
		}
		return getValue().compareTo(param4) >= 0;
	}

	@Override
	protected void changeValue(Object object) {
		long args = (long) object;
		setValue(getValue().add(BigInteger.valueOf(args)));
	}

}
